#!/usr/bin/python3

import requests

processInstanceUrl = "https://oapi.dingtalk.com/topapi/processinstance/get?access_token="

accessToken = input("请输入钉钉accessToken:")

processInstanceUrl = processInstanceUrl + accessToken

processInstanceIds = ["b813a7fa-59b7-4644-b73f-4ebdc691e180", "79f6faa2-20b5-4844-a359-625673cb6089", "887360d5-49e9-4b2a-89bd-b94cc44eeb4f", "71349902-c45a-48e4-901b-4745776bbdbf", "4e3ff35d-8f96-4187-b137-5ce715f2763b", "fa64b785-ea0a-456c-aca8-9999b00e68f1", "1a219cbf-c6ed-4902-8935-6bb3f8b9efc3", "11e35e46-2fd6-4e83-be84-63300ad8dc0a", "c0d61c1f-387f-422d-9488-6bdf197e88ab", "bb202bed-dde7-4edd-b6d1-41d24cb3457e", "27cc64b3-c1e4-462f-b204-4ac542b33597", "1db0de35-22ac-4d75-af34-e7258c89a636", "ff171927-a281-4730-a9a1-53ce3cf761d4", "5b56b6e4-9400-4a28-85ea-9cb3a4e5681b", "7bed7911-58d0-48b1-a634-4042e45920e0", "ab4a7efd-eddf-4082-8e6e-e012484afacb", "63541676-8b8a-40e0-ba8f-3c0f78cf9865", "e7e56dd7-7bbf-406f-adc0-ce2b2f9b8b76", "b04e5c66-c8ef-4f96-a8ca-99c432cca5db", "e8b52da8-b735-4b9a-9bbf-4f8bae05d8db", "3d191b88-cdb3-4fbb-ab96-d89d5e9a20d9", "b140d5b7-efac-4893-b5c2-d015e1d6d60b"]

for processId in processInstanceIds:
    data = {"access_token": accessToken, "process_instance_id": processId}
    rep = requests.post(processInstanceUrl, data=data)
    text = rep.text
    # print(text)
    resultJson = rep.json()
    if 'process_instance' not in resultJson or 'finish_time' not in resultJson['process_instance']:
        #     print('')
        # else:
        print("\t##\t" + text)
        continue
    finishTime = resultJson['process_instance']['finish_time']
    result = resultJson['process_instance']['result']
    status = resultJson['process_instance']['status']
    resultDict = {"process_instance_id": processId, "finishTime": finishTime, "result": result, "status": status}
    formValues = resultJson['process_instance']['form_component_values']
    for formValue in formValues:
        if formValue['name'] == '订单号':
            orderNumber = formValue['value']
            resultDict['orderNumber'] = orderNumber
            break
    if 'orderNumber' in resultDict:
        print(resultDict)
    else:
        print(text)
        print(resultDict)


